﻿<?xml version="1.0" encoding="utf-8"?>
<!--
* Obilogic.SPYamIt!
* ==========
*
* Obilogic (http://community.obilogic.co.uk/)
* Copyright © Obilogic Ltd. All Rights Reserved.
*
* RSS(http://community.obilogic.co.uk/blogs/MainFeed.aspx)
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
-->
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
  Location="ScriptLink"
  ScriptBlock="function ribbonSPYamItgetSelectedItems(){
  var items = SP.ListOperation.Selection.getSelectedItems();
  var yamit_body = '';
  for(var k = 0; k &lt; items.length; k++) {
    var dv = document.getElementById(items[k]['id']);
    var tagsA = dv.getElementsByTagName('A');
    yamit_body += tagsA[0].href + '\n\n';
  }
  yamit_body += SPYamItFooter();
  window.open('https://www.yammer.com/home/bookmarklet?t=SPYamIt&amp;u=' + escapeProperly(yamit_body),'SPYamIt','width=650,height=550,toolbar=1,status=1,resizable'); 
  }
  function SPYamItFooter(){
  return '\n\n(#SPYamIt)';
  }
  function ribbonSPYamItDispForm(yamit_val){
    if(yamit_val.indexOf('&amp;Source=',8) &lt; 0){
    yamit_body = yamit_val;
    }else{
    yamit_body = yamit_val.substr(0,yamit_val.indexOf('&amp;Source=',8));}
    yamit_body += SPYamItFooter();    
    window.open('https://www.yammer.com/home/bookmarklet?t=SPYamIt&amp;u=' + escapeProperly(yamit_body),'SPYamIt','width=650,height=550,toolbar=1,status=1,resizable'); 
  }
  var list=null;
  var currsiteurl=null;
  function ribbonSPYamItLibrary(siteurl, yamit_libId){
    currsiteurl=siteurl;
    var ctx = SP.ClientContext.get_current();
    list = ctx.get_web().get_lists().getById(yamit_libId);
    ctx.load(list);
    ctx.executeQueryAsync(Function.createDelegate(this, this.ribbonSPYamItLibraryonSuccessMethod), Function.createDelegate(this, this.ribbonSPYamItLibraryonFailureMethod));
  } 
  function ribbonSPYamItLibraryonSuccessMethod(sender, args) {
    var yamit_body = ''; 
    listurl = list.get_defaultViewUrl()
    if(currsiteurl.indexOf('/',8) &lt; 0){
    yamit_body = currsiteurl;
    }else{
    yamit_body = currsiteurl.substr(0,currsiteurl.indexOf('/',8));
    }
    yamit_body += listurl;
    yamit_body += SPYamItFooter(); 
    window.open('https://www.yammer.com/home/bookmarklet?t=SPYamIt&amp;u=' + escapeProperly(yamit_body),'SPYamIt','width=650,height=550,toolbar=1,status=1,resizable'); 
  }
  function ribbonSPYamItLibraryonFailureMethod(sender, args) {
    alert('request failed ' + args.get_message() + 'n' + args.get_stackTrace());
  }"
  Sequence="101">
  </CustomAction>
  <CustomAction
    Id="ObilogicSPYamIt_DocItemsRibbonButton"
    RegistrationType="ContentType"
    RegistrationId="0x01"
    Location="CommandUI.Ribbon"
    Rights="ViewListItems">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
         Location="Ribbon.Documents.Share.Controls._children">
          <Button
           Id="Ribbon.Documents.Share.Controls.SPYamIt_ItemsRibbonButton"
           Alt="'Yam It!' - Submit link to Yammer"
           Sequence="93"
           Image16by16="~sitecollection/Style Library/SPYamItAssets/yamit-ico.png"
           Image32by32="~sitecollection/Style Library/SPYamItAssets/yamit.png"
           Command="DocItemsRibbonSPYamIt"
           LabelText="'Yam It!'"
           Description="Yam It!' - Submit link to Yammer"
           TemplateAlias="o2"/>
        </CommandUIDefinition>
        <CommandUIDefinition
         Location="Ribbon.WikiPageTab.Share.Controls._children">
          <Button
           Id="Ribbon.WikiPageTab.Share.Controls.SPYamIt_ItemsRibbonButton"
           Alt="'Yam It!' - Submit link to Yammer"
           Sequence="93"
           Image16by16="~sitecollection/Style Library/SPYamItAssets/yamit-ico.png"
           Image32by32="~sitecollection/Style Library/SPYamItAssets/yamit.png"
           Command="DocItemsRibbonSPYamIt"
           LabelText="'Yam It!'"
           Description="Yam It!' - Submit link to Yammer"
           TemplateAlias="o2"/>
        </CommandUIDefinition>
        <CommandUIDefinition
         Location="Ribbon.ListItem.Actions.Controls._children">
          <Button
           Id="Ribbon.ListItem.Actions.Controls.SPYamIt_ItemsRibbonButton"
           Alt="'Yam It!' - Submit link to Yammer"
           Sequence="93"
           Image16by16="~sitecollection/Style Library/SPYamItAssets/yamit-ico.png"
           Image32by32="~sitecollection/Style Library/SPYamItAssets/yamit.png"
           Command="DocItemsRibbonSPYamIt"
           LabelText="'Yam It!'"
           Description="Yam It!' - Submit link to Yammer"
           TemplateAlias="o2"/>
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
          Command="DocItemsRibbonSPYamIt"
          CommandAction="javascript:ribbonSPYamItgetSelectedItems();"
          EnabledScript="javascript:function oneOrMoreEnable() { 
          var items = SP.ListOperation.Selection.getSelectedItems(); 
          var ci = CountDictionary(items); 
          return (ci > 0); 
          } 
          oneOrMoreEnable();"
          />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>

  <CustomAction
  Id="ObilogicSPYamIt_ItemDisplyFormRibbonButton"
  RegistrationType="ContentType"
  RegistrationId="0x01"
  Location="CommandUI.Ribbon.DisplayForm"
  Sequence="0"
  Rights="ViewListItems">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.ListForm.Display.Manage.Controls._children">
          <Button Id="Ribbon.ListForm.Display.Manage.Controls.SPYamIt_ItemDisplyFormRibbonButton"
          Alt="'Yam It!' - Submit link to Yammer"
          Image16by16="~sitecollection/Style Library/SPYamItAssets/yamit-ico.png"
          Image32by32="~sitecollection/Style Library/SPYamItAssets/yamit.png"
          Command="ItemDisplyFormRibbonSPYamIt"
          Sequence="0"
          LabelText="Yam It!"
          Description="Yam It!' - Submit link to Yammer"
          TemplateAlias="o1"/>
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler Command="ItemDisplyFormRibbonSPYamIt" CommandAction="javascript:ribbonSPYamItDispForm(document.URL);" />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>

  <CustomAction
  Id="ObilogicSPYamIt_LibraryRibbonButton"
  RegistrationType="ContentType"
  RegistrationId="0x01"
  Location="CommandUI.Ribbon"
  Sequence="0"
  Rights="ViewListItems">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.Library.Share.Controls._children">
          <Button Id="Ribbon.Library.Share.Controls.SPYamIt_LibraryRibbonButton"
          Alt="'Yam It!' - Submit link to Yammer"
          Image16by16="~sitecollection/Style Library/SPYamItAssets/yamit-ico.png"
          Image32by32="~sitecollection/Style Library/SPYamItAssets/yamit.png"
          Command="LibraryRibbonSPYamIt"
          Sequence="0"
          LabelText="Yam It!"
          Description="Yam It!' - Submit link to Yammer"
          TemplateAlias="o2"/>
        </CommandUIDefinition>
        <CommandUIDefinition Location="Ribbon.List.Share.Controls._children">
          <Button Id="Ribbon.List.Share.Controls.SPYamIt_LibraryRibbonButton"
          Alt="'Yam It!' - Submit link to Yammer"
          Image16by16="~sitecollection/Style Library/SPYamItAssets/yamit-ico.png"
          Image32by32="~sitecollection/Style Library/SPYamItAssets/yamit.png"
          Command="LibraryRibbonSPYamIt"
          Sequence="0"
          LabelText="Yam It!"
          Description="Yam It!' - Submit link to Yammer"
          TemplateAlias="o2"/>
        </CommandUIDefinition>
        <CommandUIDefinition Location="Ribbon.Calendar.Calendar.Share.Controls._children">
          <Button Id="Ribbon.Calendar.Calendar.Share.Controls.SPYamIt_LibraryRibbonButton"
          Alt="'Yam It!' - Submit link to Yammer"
          Image16by16="~sitecollection/Style Library/SPYamItAssets/yamit-ico.png"
          Image32by32="~sitecollection/Style Library/SPYamItAssets/yamit.png"
          Command="LibraryRibbonSPYamIt"
          Sequence="0"
          LabelText="Yam It!"
          Description="Yam It!' - Submit link to Yammer"
          TemplateAlias="o1"/>
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler Command="LibraryRibbonSPYamIt" CommandAction="javascript:ribbonSPYamItLibrary('{SiteUrl}','{ListId}');" />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>
</Elements>
